﻿/*
AJAX: Xu ly load danh sach san pham
*/
var xmlHttp
function getBody(content) {
    test = content.toLowerCase();    // to eliminate case sensitivity
    var x = test.indexOf("<body");
    if (x == -1) return "";

    x = test.indexOf(">", x);
    if (x == -1) return "";

    var y = test.lastIndexOf("</body>");
    if (y == -1) y = test.lastIndexOf("</html>");
    if (y == -1) y = content.length;    // If no HTML then just grab everything till end

    return content.slice(x + 1, y);
} 

function GetXmlHttpObject() {
    var request = false;
    try {
        request = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (err2) {
        try {
            request = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (err3) {
            try {
                request = new XMLHttpRequest();
            }
            catch (err1) {
                request = false;
            }
        }
    }
    return request;
}

function SelectSanPhamByLoaiSP_NSX(loaisp, nsx) 
{
    //alert(loaisp+","+nsx);
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    url = "SelectSanPhamByLoaiSP_NSX.aspx";
    url += "?loaisp=" + loaisp;
    url += "&nsx=" + nsx;
    //alert(url);
    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //alert(xmlHttp.responseText);
            document.getElementById("contentCenter").innerHTML = getBody(xmlHttp.responseText);
            //alert(document.getElementById("contentCenter").innerHTML);
        }
    };

    xmlHttp.send(null);

}
function MoveToPage(str) {
    //alert("tuan");
    status = 0;
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }

    xmlHttp.open("GET", str, true);

    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            document.getElementById("contentCenter").innerHTML =
                getBody(xmlHttp.responseText);
        }
    };

    xmlHttp.send(null);


}
function XemChiTietSanPham(id) {
    //alert(loaisp+","+nsx);
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    url = "XemChiTietSanPham.aspx";
    url += "?id=" + id;
    //alert(url);
    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //alert(xmlHttp.responseText);
            document.getElementById("contentCenter").innerHTML = getBody(xmlHttp.responseText);
            //alert(document.getElementById("contentCenter").innerHTML);
        }
    };

    xmlHttp.send(null);

}
function GoToPageSanPhamByLoaiSP_NSX(loaisp, nsx, page) {
    //alert(loaisp+","+nsx);
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    url = "SelectSanPhamByLoaiSP_NSX.aspx";
    url += "?loaisp=" + loaisp;
    url += "&nsx=" + nsx;
    url += "&Page=" + page;
    //alert(url);
    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //alert(xmlHttp.responseText);
            document.getElementById("contentCenter").innerHTML = getBody(xmlHttp.responseText);
            //alert(document.getElementById("contentCenter").innerHTML);
        }
    };

    xmlHttp.send(null);

}
function GoToPageKetQuaTimKiem(page) {
    //alert(loaisp+","+nsx);
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    url = "KetQuaTimKiem.aspx";
    url += "&Page=" + page;
    //alert(url);
    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //alert(xmlHttp.responseText);
            document.getElementById("contentCenter").innerHTML = getBody(xmlHttp.responseText);
            //alert(document.getElementById("contentCenter").innerHTML);
        }
    };

    xmlHttp.send(null);

}